package elizaengine;

import java.util.ArrayList;

import elizascript.KeywordObject;
import elizascript.ScriptInterop;

/**
 * The class InputProcessor calculates and contains formatted
 * forms of the user input.
 * 
 * @author Caroline
 * 
 */
public class InputProcessor {
	// the user input and processed forms
	private String userInput;
	private String[] separatedUserInput;
	private ArrayList<KeywordObject> keywords;

	// provides access to the eliza script
	private ScriptInterop script;

	public InputProcessor(ScriptInterop script) {
		this.script = script;
	}

	// divides the users input into separate words
	private void separateUserInput() {
		separatedUserInput = userInput.split(" ");
	}

	// looks for keywords in the user input
	private void findKeyWords() {
		keywords = new ArrayList<KeywordObject>();
		for (int i = 0; i < separatedUserInput.length; i++) {
			if (script.getKeywordPriority(separatedUserInput[i]) != -1) {
				keywords.add(script.getKeywordObject(separatedUserInput[i]));
			}
		}
	}

	// sets the userInput and all related filds to match a new input
	protected void setUserInput(String userInput) {
		this.userInput = userInput;
		separateUserInput();
		findKeyWords();
	}

	// accessor methods to the fields relating the user input in various forms
	protected String getUserInput() {
		return userInput;
	}

	protected String[] getSeparatedUserInput() {
		return separatedUserInput;
	}

	protected ArrayList<KeywordObject> getKeywords() {
		return keywords;
	}
}
